#include<iostream>
#include<thread>
#include<mutex>
#include<condition_variable>
using namespace std;


void Print1(int& x)
{
	for (int n = 0; n < 10; n++)
	{

		cout << n << endl;
	}

	cout << "Print1_id==="<<this_thread::get_id()<<endl;
}

void Print2(int& x)
{
	for (int n = 0; n < 10; n++)
	{
		cout << x << endl;
	}

	cout << "Print2_id=="<< this_thread::get_id()  <<endl;
}

void Print3(const string& str)
{
	cout << str << endl;
}

int main()
{
	/*int x = 1;
	thread t(Print1, ref(x));
	thread t2(Print2, ref(x));

	cout << "t_id=" << t.get_id() << endl;
	cout << "t2_id="<< t2.get_id() << endl;
	t.join();
	t2.join();*/

	thread t(Print3, "dasdasdads");




	thread t2 = move(t);
	t2.join();


	int x = 1;
	mutex mtx;
	condition_variable cond;
	thread t4([&]() {
		for (int i = 0; i < 10; i++)
		{
			unique_lock<mutex> un(mtx);
			if (x % 2 == 0)
			{
				cond.wait(un);
			}
			cout << this_thread::get_id() << " =" << x << endl;
			x++;
			cond.notify_one();
		}
		});

	thread t5([&]() {
		for (int i = 0; i < 10; i++)
		{
			unique_lock<mutex> un(mtx);
			if (x % 2 != 0)
				cond.wait(un);
			cout << this_thread::get_id() << " =" << x << endl;
			x++;
			cond.notify_one();
		}
		});



	t4.join();
	t5.join();

	cout << x << endl;

	return 0;
}